// ActionScript file
import mx.controls.Alert;
import mx.managers.PopUpManager;

import org.flexlancer.Logger.Logger;
import org.flexlancer.databases.Suppliers;

private var suplName:String;
[Bindable]
private var suplInfo:Array = new Array();

private function OnAddSupplierContact():void{
	try{
			//Alert.show(this.rgContactTypeGroup.selectedValue.toString());
			var info:Object = new Object();
			info.type = this.rgContactTypeGroup.selectedValue.toString();
			if(this.taContactDetails.text.length > 0){
				info.detail = this.taContactDetails.text;
				this.suplInfo.push(info);
			}else	{
				Alert.show("Details are missing!","Field Empty");
			}
			this.dgContactsInfo.dataProvider = this.suplInfo;
			this.taContactDetails.text = "";
			this.taContactDetails.setFocus();

			var arrNext:Array = ["Address","Mobile","PTCL","Email","Fax","Other"]; 
			var ind:Number = arrNext.indexOf(this.rgContactTypeGroup.selectedValue);
			ind = (ind + 1) % arrNext.length;
			this.rgContactTypeGroup.selectedValue = arrNext [ ind ];
			//Alert.show(this.custInfo.toString());
	}catch(err:Error){
		Logger.LogE(err);
	}
}
private function OnSaveClick():void{
	try{
		if(this.txtSupplierName.text.length<1){
			Alert.show("Name Field is Empty","Empty Field");
		}else
		{
			this.suplName = this.txtSupplierName.text;
		}
		//Alert.show(this.cmbCustomerType.text);
		Suppliers.AddSupplier(this.suplName, this.suplInfo);
		//var temp:Array = DatabaseManager.Manager.Select("customers");
		//var temp2:Array = DatabaseManager.Manager.Select("contactinfo");
		//Alert.show(temp.toString(),"customer record");
		//Alert.show(temp2.toString(),"customerinfo");
		if(this.chkAddAnother.selected){
			this.txtSupplierName.text = "";
			this.suplInfo = new Array();
			//this.dgContactsInfo.dataProvider = cust
			
			
		}else{
			PopUpManager.removePopUp(this);
		}	
			
	}catch(err:Error){
		Logger.LogE(err);
	}
}